#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

typedef unsigned int bitset_elem_t;

#define BPE (sizeof(bitset_elem_t)*8) /* bits per element */

#define BITSET_TEST(bs, i) ((bs[(i)/BPE] & ((bitset_elem_t)1 << ((i)%BPE))) != 0)
#define BITSET_SET(bs, i)  (bs[(i)/BPE] |= ((bitset_elem_t)1 << ((i)%BPE)))
#define BITSET_INIT(bits)  ((bitset_elem_t*)calloc(((bits)+BPE-1)/BPE, sizeof(bitset_elem_t)))
#define BITSET_FREE(bs)    free(bs)

int main()
{
    int N, NC, size, i;
    int hash, count, nc;
    char buf[100];
    int map[256], c;  /* map[c] = character code (0 ~ NC-1) of c */
    bitset_elem_t *exists;

    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d", &N, &NC);
    if (N == 0) /* zero-length substring wanted */
    {
        printf("1\n");
        return 0;
    }

    /* Compute the size of the bitset: size = NC^N */
    for (size = 1, i = 0; i < N; i++)
        size *= NC;
    memset(map, -1, sizeof(map));

    /* Build first hash code. */
    nc = 0; /* number of appeared characters */
    hash = 0;
    for (i = 0; i < N; i++)
    {
        if ((c = fgetc(stdin)) == -1) /* text shorter than N */
            break;
        if (map[c] == -1) 
            map[c] = nc++;
        hash *= NC;
        hash += map[c];
    }
    if (i < N) /* text shorter than N */
    {
        printf("0\n");
        return 0;
    }

    /* Initialize the bitset. */
    exists = BITSET_INIT(size);
    BITSET_SET(exists, hash);
    count = 1;

    /* Read remaining string one by one. */
    while ((c = fgetc(stdin)) != -1 && c != 0 && c != '\n')
    {
        if (map[c] == -1)
            map[c] = nc++;
        hash = (hash % (size / NC)) * NC + map[c];
        if (!BITSET_TEST(exists, hash))
        {
            BITSET_SET(exists, hash);
            count++;
        }
    }
    printf("%d\n", count);

    BITSET_FREE(exists);
    return 0;
}
